package com.demo;

import java.util.Scanner;

public class bank3 {
        public static void method1(){
        Scanner input = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String name= input.next();
        System.out.println("请输入密码：");
        String password=input.next();

    }
    private static final String userName = "爸爸";

    private static int userMoney = 2000;

    private static final int maxMoney = 5000;

    private static final String userCard = "12345";

    private static final int userPwd = 123;

    public static void main(String[] args) {
        System.out.println("欢迎光临中国建设银行！");

        System.out.println("请输入银行卡号！");

        Scanner scan = new Scanner(System.in);

        String card = scan.next();

        System.out.println("请输入密码！");

        int pwd = scan.nextInt();

        while (!checkCardPwd(card, pwd)) {
            System.out.println("银行卡号或密码错误,请重新输入！");

            System.out.println("请输入银行卡号");

            card = scan.next();

            System.out.println("请输入银行卡密码");

            pwd = scan.nextInt();

        }

        System.out.println("登陆成功");

        System.out.println("当前登陆用户名:" + userName);

        operation();

    }

//验证账号密码

    public static boolean checkCardPwd(String card, int pwd) {
        return card.equals(userCard) && userPwd == pwd;

    }

//进行操作选择

    public static void operation() {
        System.out.println("请选择您需要操作的业务！");

        System.out.println("存款:1 取款:2 余额:3 退出:0");

        Scanner scan = new Scanner(System.in);

        int num = scan.nextInt();

        while (num != 0 && num != 1 && num != 2 && num != 3) {
            System.out.println("非法输入！请重新输入");

            num = scan.nextInt();

        }

        switch (num) {
            case 1:

                System.out.println("您当前的余额为：" + userMoney + "元");

                System.out.println("请输入存款金额");

                int putMoney = scan.nextInt();

                while (putMoney > maxMoney) {
                    System.out.println("单次存款金额上限金额不能大于5000元，请重新输入！");

                    putMoney=scan.nextInt();

                }

                userMoney = userMoney + putMoney;

                System.out.println("存款成功！当前银行卡余额为：" + userMoney + "元");

                switchType();

                break;

            case 2:

                System.out.println("您当前可取款余额为：" + userMoney + "元");

                System.out.println("请输入取款金额");

                int outMoney = scan.nextInt();

                while (outMoney > userMoney) {
                    System.out.println("您输入的金额过多,请查看您的余额后输入正确的取款金额!");

                    outMoney = scan.nextInt();

                }

                userMoney = userMoney - outMoney;

                System.out.println("取款成功！当前银行卡余额为：" + userMoney + "元");

                switchType();

                break;

            case 3:

                System.out.println("您当前的余额为：" + userMoney + "元");

                switchType();

                break;

            case 0:

                System.out.println("成功退出！欢迎下次光临！");

                break;

            default:

                System.out.println("输入异常！");

        }

    }

    public static void switchType() {
        System.out.println("请选择操作：返回上一层业务:1 退出:0");

        Scanner scan = new Scanner(System.in);

        switch (scan.nextInt()) {
            case 1:

                operation();

                break;

            case 0:

                System.out.println("成功退出！欢迎下次光临！");

                break;

            default:

                System.out.println("输入异常");

        }

    }

}


